package com.suoluo.zenadmin.controllers.admin.home;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.dest.DestFeatureCategoryService;
import com.suoluo.zenadmin.service.home.HomeService;
import com.suoluo.zenadmin.vo.PageVO;
import com.suoluo.zenadmin.vo.home.HomeCategoryVO;
import com.suoluo.zenadmin.vo.home.HomeItemVO;

@Path("/")
public class HomeController {

	@Resource(name="homeService")
	private HomeService homeService;
	
	@Resource(name="categoryService")
	private DestFeatureCategoryService categoryService;
	
	@Get("category/vlist")
	public String toListHomeCategory()
	{
		return "listHomeCategory";
	}
	@JSON
	@Post("category/list")
	public Object listHomeCategory()
	{
		return homeService.findListHomeCategory();
	}
	@Get("category/vsave")
	public String toAddHomeCategory()
	{
		return "addHomeCategory";
	}
	@JSON
	@Post("category/save")
	public Object saveHomeCategory(HomeCategoryVO categoryPOJO)
	{
		homeService.saveHomeCategory(categoryPOJO);
		return CommonResp.SUCCESS;
	}
	@Get("category/vupdate")
	public String toUpdateHomeCategory(Invocation invo,@Param("categoryId")int categoryId)
	{
		HomeCategoryVO category = homeService.findHomeCategoryById(categoryId);
		invo.addModel("homeCategory",category);
		return "updateHomeCategory";
	}
	@JSON
	@Post("category/update")
	public Object updateHomeCategory(HomeCategoryVO categoryPOJO)
	{
		homeService.updateHomeCategory(categoryPOJO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("category/delete")
	public Object deleteHomeCategory(@Param("categoryId")int categoryId)
	{
		homeService.deleteHomeCategory(categoryId);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("add/listfeaturecategory")
	public Object listFeatureCategory()
	{
		return categoryService.findAllRootCategory();
	}
	@Get("category/item/vlist")
	public String toListHomeCategoryItem(Invocation invo,
			@Param("categoryId")int categoryId,@Param("featureCategoryId")int featureCategoryId)
	{
		invo.addModel("categoryId",categoryId);
		invo.addModel("featureCategoryId",featureCategoryId);
		return "listHomeItem";
	}
	@JSON
	@Post("category/item/list")
	public Object listHomeCategoryItem(@Param("categoryId")int categoryId)
	{
		return homeService.findListHomeCategoryItem(categoryId);
	}
	@Get("category/item/vsave")
	public String toAddHomeCategory(Invocation invo,@Param("categoryId")int categoryId,
			@Param("featureCategoryId")int featureCategoryId)
	{
		invo.addModel("categoryId",categoryId);
		invo.addModel("featureCategoryId",featureCategoryId);
		return "addHomeItem";
	}
	@JSON
	@Post("category/item/add/list")
	public Object listFeatureCategory(PageVO page,@Param("featureCategoryId")int featureCategoryId,
			@Param("tempName")String tempName)
	{
		return homeService.findAddFeatureCategoryList(page,featureCategoryId,tempName);
	}
	@JSON
	@Post("category/item/save")
	public Object saveHomeCategoryItem(HomeItemVO itemVO)
	{
		 homeService.saveHomeCategoryItem(itemVO);
		 return CommonResp.SUCCESS;
	}
}
